/*
 * Miner.java
 *
 * Created on March 27, 2007, 10:29 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package ai9hells.pgaibe.chapter2.westworldwithmessaging;

import ai9hells.pgaibe.common.fsm.StateMachine;
import ai9hells.pgaibe.common.messaging.Telegram;

/**
 *
 * @author andre.bandarra
 */
public class Miner extends BaseGameEntity{
    public static final int COMFORT_LEVEL = 5;
    private static final int MAX_NUGGETS = 3;
    private static final int THIRST_LEVEL = 5;
    private static final int TIREDNESS_THRESHOLD = 5;
    private StateMachine<Miner> stateMachine = new StateMachine<Miner>(this);
    
    private Locations location = Locations.SHACK;
    private int goldCarried = 0;
    private int moneyInBank = 0;
    private int thirst = 0;
    private int fatigue = 0;


    /** Creates a new instance of Miner */
        
    public Miner(int id) {
        super(id);
        stateMachine.setCurrentState(GoHomeAndSleepTilRested.INSTANCE);
    }

    public boolean handleMessage(Telegram msg) {
        return stateMachine.handleMessage(msg);
    }
    
    public StateMachine<Miner> getStateMachine(){
        return this.stateMachine;
    }
    
    public void update() {
        thirst++;        
        stateMachine.update();
    }


    public Locations getLocation() {
        return location;
    }

    public void setLocation(Locations location) {
        this.location = location;
    }

    public int getGoldCarried() {
        return goldCarried;
    }

    public void setGoldCarried(int goldCarried) {
        this.goldCarried = goldCarried;
    }
    
    public void addGoldCarried(int quantity){
        this.goldCarried += quantity;
    }
    
    public boolean isPocketFull(){
        return (goldCarried >= MAX_NUGGETS);
    }

    public int getMoneyInBank() {
        return moneyInBank;
    }

    public void setMoneyInBank(int moneyInBank) {
        this.moneyInBank = moneyInBank;
    }
    public void addMoneyInBank(int amount){
        this.goldCarried -= amount;
        this.moneyInBank += amount;
    }

    public boolean isThirsty(){
        return thirst >= THIRST_LEVEL;
    }

    public void increaseFatigue(){
        fatigue++;
    }
    
    public void decreaseFatigue(){
        fatigue--;
    }
    
    public boolean isFatigued(){
        return fatigue > TIREDNESS_THRESHOLD;
    }
    
    public void buyAndDrinkWhiskey(){
        thirst = 0;
        moneyInBank -= 2;
    }
    
}
